package com.sansecy.video.player.factory;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;

import com.google.android.exoplayer2.DefaultRenderersFactory;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.Renderer;
import com.google.android.exoplayer2.audio.AudioRendererEventListener;
import com.google.android.exoplayer2.metadata.MetadataOutput;
import com.google.android.exoplayer2.text.SubtitleDecoder;
import com.google.android.exoplayer2.text.SubtitleDecoderFactory;
import com.google.android.exoplayer2.text.TextOutput;
import com.google.android.exoplayer2.text.TextRenderer;
import com.google.android.exoplayer2.video.VideoRendererEventListener;
import com.sansecy.video.ssa.SsaDecoder;

import java.util.ArrayList;

public class SpRenderersFactory extends DefaultRenderersFactory {

    public SpRenderersFactory(Context context) {
        super(context);
    }

    public SpRenderersFactory(Context context, int extensionRendererMode) {
        super(context, extensionRendererMode);
    }

    public SpRenderersFactory(Context context, int extensionRendererMode, long allowedVideoJoiningTimeMs) {
        super(context, extensionRendererMode, allowedVideoJoiningTimeMs);
    }

    @Override
    public Renderer[] createRenderers(Handler eventHandler, VideoRendererEventListener videoRendererEventListener, AudioRendererEventListener audioRendererEventListener, TextOutput textRendererOutput, MetadataOutput metadataRendererOutput) {
        return super.createRenderers(eventHandler, videoRendererEventListener, audioRendererEventListener, textRendererOutput, metadataRendererOutput);
    }

    @Override
    protected void buildTextRenderers(Context context, TextOutput output, Looper outputLooper, int extensionRendererMode, ArrayList<Renderer> out) {
        out.add(new TextRenderer(output, outputLooper, new SubtitleDecoderFactory() {
            @Override
            public boolean supportsFormat(Format format) {
                return true;
            }

            @Override
            public SubtitleDecoder createDecoder(Format format) {
                return new SsaDecoder();
            }
        }));
    }
}
